/*
 * @Author: your name
 * @Date: 2020-08-23 20:39:12
 * @LastEditTime: 2020-08-28 08:46:40
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \新建文件夹\two-app\src\store\getAuth\getAuth.js
 */
// router
import router from '../../router/index'
// 设置好的全部的路由
import homeRoutes from '../../router/homeRoutes/homeRoutes'

// 还得引入  -----筛选路由的方法
import { filterRoutes } from '../../utils/filterRoutes'

const state = {
  filterRoute: []
}

const mutations = {
  filter_routes(state, payload) {
    console.log(payload, '---我被执行了')
    state.filterRoute = payload
  }
}
const actions = {
  // userInfo----身份的名称
  getRoutes({ commit }, userInfo) {
    const res = filterRoutes(homeRoutes, userInfo)
    // 调用addRoutes动态添加路由,把咱们的路由给添加到router/index.js里面
    router.addRoutes(res)
    // sessionStorage.setItem('router', JSON.stringify(res))
    commit('filter_routes', res)
    // console.log(res)
    router.push(res[0].path)
    // router.push(res[0].path).catch(err => { return err })
    // console.log(router)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
